package api.collection;
/**
 * 数组转换为集合
 */

import java.util.Arrays;
import java.util.List;

public class ArrayToList {
    public static void main(String[] args) {
        String[] arrya = {"one", "two", "three", "four", "five"};
        System.out.println(Arrays.toString(arrya));
        //asList()方法会返回内部的ArrayList,内部直接引用给定的数组的arrya
        List<String> list = Arrays.asList(arrya);
        System.out.println(list);
        arrya[1]="six";
        System.out.println("arrya:"+Arrays.toString(arrya));
        System.out.println("list:"+list);
        list.set(2,"阿芬");
        System.out.println("arrya:"+Arrays.toString(arrya));
        System.out.println("list:"+list);

        //给集合添加/删除元素相当于给数组添加/删除
        //而数组是定长度的,不会自动扩容/缩容，因此发生不支持操作异常
        //list.add("af");//运行时发生不支持异常

    }
}
